/*
** cmd.c for  in /home/faye_m//zappy
** 
** Made by mouhamed faye
** Login   <faye_m@epitech.net>
** 
** Started on  Mon Jun 20 20:51:43 2011 mouhamed faye
** Last update Thu Jun 30 22:53:26 2011 mouhamed faye
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "cmd.h"
#include "team.h"

list_request	*add_request(list_request *req, char *cmd) // ajout entete
{
  list_request *updated_list; 
  updated_list = malloc(sizeof(list_request));
  if(!updated_list)
    printf ("fonction add_command segfault segfault the zappy ....\n");
  updated_list->cmd = cmd;
  updated_list->delay = 100; // default : call get_cmd_delay function
  updated_list->num_client  = 1;
  updated_list->nb_req +=1;
  updated_list->next = NULL;
  if (req == NULL)
    {
       return (updated_list);
    }
  else
    {
      list_request *tmp = req; 
      while (tmp->next != NULL)
	{
	  tmp = tmp->next;
	}
      tmp->next = updated_list;
      return(req);
    }
}

list_request	*del_request(list_request *req, char *cmd)
{
  if (req == NULL)
    return NULL;
  
  if (req != NULL)
    {
      list_request *to_return =  req->next;
      free(req);
      return (to_return);
    }
  else
    {
      return (NULL);
    }
}

void	display_request(list_request *all_request)
{
  list_request		*tmp = all_request;
  int			i;
  i = 0;
    while (tmp != NULL)
    {
      printf ("cmd n: %d : %s\n", i++, tmp->cmd);
      tmp = tmp->next;
    }
}
  
